/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package com.camachosanchez.gui;

import com.camachosanchez.bean.Pilotos;
import com.camachosanchez.controler.jdbc.PilotosJdbcControler;
import com.camachosanchez.controler.jpa.PilotosJpaController;
import com.camachosanchez.gui.textfield.MaxLengthTextDocument;
import com.camachosanchez.util.Archivo;
import com.camachosanchez.util.Constantes;
import com.camachosanchez.util.EstadosJDialog;
import com.camachosanchez.util.EstadosJDialog.EstadoJDialog;
import com.camachosanchez.util.GUIUtil;
import java.awt.event.KeyEvent;
import java.text.SimpleDateFormat;
import java.util.Calendar;
import java.util.Date;
import java.util.GregorianCalendar;
import java.util.List;
import javax.swing.DefaultComboBoxModel;
import javax.swing.JOptionPane;
import org.jdesktop.swingx.autocomplete.AutoCompleteDecorator;

/**
 *
 * @author Zully
 */
public class EditorPiloto extends javax.swing.JDialog {

    public EstadosJDialog.EstadoJDialog Estado;
    private MaestroPilotos buscador;
    private int fila;
    private Pilotos piloto;

    /**
     * Creates new form EditorPiloto
     */
    public EditorPiloto(MaestroPilotos buscador, java.awt.Frame parent, boolean modal, Pilotos piloto, int fila) {
        super(parent, modal);
        initComponents();
        this.setLocationRelativeTo(null);
        GUIUtil.addEscapeKey(this);
        this.dateFechaNac.setDate(new Date());
        this.buscador = buscador;
        this.fila = fila;
        this.txtNombres.requestFocusInWindow();
        Archivo archivo = new Archivo();
        List<String> paises = archivo.obtenerListaPaises();
        cmbPais.setModel(new DefaultComboBoxModel(paises.toArray()));
        AutoCompleteDecorator.decorate(cmbPais);
        
        Date fechaActual = new Date();
        dateFechaNac.setMaxSelectableDate(fechaActual);
        Calendar cal = new GregorianCalendar();
        cal.add(GregorianCalendar.DAY_OF_YEAR, -36500);
        dateFechaNac.setMinSelectableDate(new Date(cal.getTimeInMillis()));
        
        MaxLengthTextDocument docLicencia = new MaxLengthTextDocument();
        docLicencia.setMaxChars(15, Constantes.ANY);
        txtTipoLic.setDocument(docLicencia);
        
//        MaxLengthTextDocument docObservacion = new MaxLengthTextDocument();
//        docObservacion.setMaxChars(200, Constantes.ANY);
//        txtpObservacion.setDocument(docObservacion);
        
        MaxLengthTextDocument docNombre = new MaxLengthTextDocument();
        docNombre.setMaxChars(50, Constantes.ANY);
        txtNombres.setDocument(docNombre);
        
        MaxLengthTextDocument docApellido = new MaxLengthTextDocument();
        docApellido.setMaxChars(50, Constantes.ANY);
        txtApellidos.setDocument(docApellido);
        
        MaxLengthTextDocument docNacionalidad = new MaxLengthTextDocument();
        docNacionalidad.setMaxChars(50, Constantes.ANY);
        txtNacionalidad.setDocument(docNacionalidad);
        
        MaxLengthTextDocument docProvincia = new MaxLengthTextDocument();
        docProvincia.setMaxChars(45, Constantes.ANY);
        txtProvincia.setDocument(docProvincia);
        
        MaxLengthTextDocument docLocalidad = new MaxLengthTextDocument();
        docLocalidad.setMaxChars(45, Constantes.ANY);
        txtLocalidad.setDocument(docLocalidad);
        
        MaxLengthTextDocument docTelefono = new MaxLengthTextDocument();
        docTelefono.setMaxChars(20, Constantes.ANY);
        txtTelefono.setDocument(docTelefono);
        
        if (piloto != null) {
            this.CargarDatosPiloto(piloto);
            this.piloto = piloto;
        }
    }

    public EstadoJDialog getEstado() {
        return Estado;
    }

    public void setEstado(EstadoJDialog Estado) {
        switch (Estado) {
            case NUEVO:
                btnElminar.setVisible(false);
//                jSeparator2.setVisible(false);
                break;
            case MODIFICAR:
                btnElminar.setVisible(true);
//                jSeparator2.setVisible(true);
                break;
        }
        this.Estado = Estado;
    }

    private void GuardarDatos() {
        switch (this.Estado) {
            case NUEVO:
                this.RegistrarPiloto(this.LeerDatosPiloto());
                Principal.getInstance().actualizarListaPilotosVentanaEgresos();
                Principal.getInstance().actualizarListaPilotosVentanaBusquedaEgresos();
                break;
            case MODIFICAR:
                this.ModificarPiloto(this.LeerDatosPiloto());
                Principal.getInstance().actualizarListaPilotosVentanaEgresos();
                Principal.getInstance().actualizarListaPilotosVentanaBusquedaEgresos();
                break;
            case ELIMINAR:
                break;
            default:
                break;
        }
    }

    private void CargarDatosPiloto(Pilotos piloto) {
//        this.jTxtCodigo.setInformacionUsuario("" + piloto.getId());
        this.txtNombres.setText(piloto.getNombres());
        this.txtApellidos.setText(piloto.getApellidos());
        this.dateFechaNac.setDate(piloto.getFechaNacimiento());
        this.txtTelefono.setText(piloto.getTelefono());
        this.txtNacionalidad.setText(piloto.getNacionalidad());
//        this.jTxtPais.setInformacionUsuario(piloto.getPaisResidencia());
        cmbPais.setSelectedItem(piloto.getPaisResidencia());
        this.txtProvincia.setText(piloto.getProvinciaResidencia());
        this.txtLocalidad.setText(piloto.getLocalidadResidencia());
        this.txtTipoLic.setText(piloto.getTipoLicencia());
        this.txtpObservacion.setText(piloto.getObservaciones());
//        this.jCheckEstado.setSelected(piloto.isEstado());
    }

    private Pilotos LeerDatosPiloto() {
        Pilotos p = new Pilotos();
//        piloto.setId((this.jTxtCodigo.getText().compareTo("") != 0) ? Integer.parseInt(this.jTxtCodigo.getText()) : 0);
        p.setNombres(this.txtNombres.getText().trim());
        p.setApellidos(this.txtApellidos.getText().trim());
        p.setFechaNacimiento(this.dateFechaNac.getDate());
        p.setTelefono(this.txtTelefono.getText().trim());
        p.setNacionalidad(this.txtNacionalidad.getText().trim());
        p.setPaisResidencia(cmbPais.getSelectedItem().toString());
        p.setProvinciaResidencia(this.txtProvincia.getText().trim());
        p.setLocalidadResidencia(this.txtLocalidad.getText().trim());
        p.setTipoLicencia(this.txtTipoLic.getText().trim());
        p.setObservaciones(this.txtpObservacion.getText());
        p.setFechaInsercionActualizacion(new Date());
        p.setIdUsuario(Constantes.currentUser);
//        piloto.setEstado(this.jCheckEstado.isSelected());
        if (this.piloto != null) {
            p.setControlCambioNeumaticoList(this.piloto.getControlCambioNeumaticoList());
            p.setInspeccionEquipoList(this.piloto.getInspeccionEquipoList());
            p.setInspeccionEquipoList1(this.piloto.getInspeccionEquipoList1());
            p.setAlineacionesList(this.piloto.getAlineacionesList());
            p.setDespinchesList(this.piloto.getDespinchesList());
            p.setEgresosList(piloto.getEgresosList());
        }
        return p;
    }

    private boolean ValidarDatos() {
        if (this.txtNombres.getText().isEmpty()) {
            JOptionPane.showMessageDialog(this, "Se requiere un nombre para el piloto.", "Datos incompletos", JOptionPane.ERROR_MESSAGE);
            txtNombres.requestFocusInWindow();
            return false;
        }
        if (this.txtApellidos.getText().isEmpty()) {
            JOptionPane.showMessageDialog(this, "Se requiere apellidos para el piloto.", "Datos incompletos", JOptionPane.ERROR_MESSAGE);
            txtApellidos.requestFocusInWindow();
            return false;
        }
        try {
            String formato = dateFechaNac.getDateFormatString();
            Date date = dateFechaNac.getDate();
            SimpleDateFormat sdf = new SimpleDateFormat(formato);
            String format = sdf.format(date);
        } catch (NullPointerException ex) {
            JOptionPane.showMessageDialog(this, "Seleccione una fecha válida.", "Error", JOptionPane.ERROR_MESSAGE);
            return false;
        }
        if (this.txtTipoLic.getText().isEmpty()) {
            JOptionPane.showMessageDialog(this, "Se requiere el tipo de licencia para el piloto.", "Datos incompletos", JOptionPane.ERROR_MESSAGE);
            txtTipoLic.requestFocusInWindow();
            return false;
        }
        return true;
    }

    private void RegistrarPiloto(Pilotos piloto) {
        PilotosJpaController dao_piloto = new PilotosJpaController(null);
        piloto.setEstado(true);
        dao_piloto.create(piloto);
        JOptionPane.showMessageDialog(this, "El piloto ha sido registrado correctamente.", "Operación finalizada", JOptionPane.INFORMATION_MESSAGE);
        buscador.llenarPilotos();
        this.dispose();
    }

    private void ModificarPiloto(Pilotos p) {
        PilotosJpaController dao_piloto = new PilotosJpaController(null);
        try {
            p.setEstado(true);
            p.setId(this.piloto.getId());
            dao_piloto.edit(p);
            JOptionPane.showMessageDialog(this, "Los datos del piloto han sido actualizados correctamente.", "Operación finalizada", JOptionPane.INFORMATION_MESSAGE);
            buscador.llenarPilotos();
            dispose();
        } catch (Exception e) {
            JOptionPane.showMessageDialog(Principal.getInstance(), e.getMessage(), "Error", JOptionPane.ERROR_MESSAGE);
        }
    }

    /**
     * This method is called from within the constructor to initialize the form.
     * WARNING: Do NOT modify this code. The content of this method is always
     * regenerated by the Form Editor.
     */
    @SuppressWarnings("unchecked")
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {

        jPanel1 = new javax.swing.JPanel();
        jPanel3 = new javax.swing.JPanel();
        jLabel7 = new javax.swing.JLabel();
        jLabel6 = new javax.swing.JLabel();
        txtProvincia = new javax.swing.JTextField();
        txtLocalidad = new javax.swing.JTextField();
        jLabel9 = new javax.swing.JLabel();
        cmbPais = new javax.swing.JComboBox();
        jPanel4 = new javax.swing.JPanel();
        jLabel2 = new javax.swing.JLabel();
        jLabel3 = new javax.swing.JLabel();
        txtNombres = new javax.swing.JTextField();
        txtApellidos = new javax.swing.JTextField();
        dateFechaNac = new com.toedter.calendar.JDateChooser();
        jLabel4 = new javax.swing.JLabel();
        jLabel10 = new javax.swing.JLabel();
        txtTelefono = new javax.swing.JTextField();
        txtNacionalidad = new javax.swing.JTextField();
        jLabel5 = new javax.swing.JLabel();
        jPanel5 = new javax.swing.JPanel();
        jLabel11 = new javax.swing.JLabel();
        txtTipoLic = new javax.swing.JTextField();
        jTabbedPane1 = new javax.swing.JTabbedPane();
        jScrollPane2 = new javax.swing.JScrollPane();
        txtpObservacion = new javax.swing.JTextPane();
        jToolBar1 = new javax.swing.JToolBar();
        jPanel2 = new javax.swing.JPanel();
        btnGuardar = new javax.swing.JButton();
        btnElminar = new javax.swing.JButton();

        setDefaultCloseOperation(javax.swing.WindowConstants.DISPOSE_ON_CLOSE);
        setTitle(".:: Piloto ::.");
        setResizable(false);

        jPanel3.setBorder(javax.swing.BorderFactory.createTitledBorder("Información de Residencia"));
        jPanel3.setOpaque(false);

        jLabel7.setText("Pais:");

        jLabel6.setText("Provincia:");

        txtProvincia.addKeyListener(new java.awt.event.KeyAdapter() {
            public void keyPressed(java.awt.event.KeyEvent evt) {
                txtProvinciaKeyPressed(evt);
            }
            public void keyTyped(java.awt.event.KeyEvent evt) {
                txtProvinciaKeyTyped(evt);
            }
        });

        txtLocalidad.addKeyListener(new java.awt.event.KeyAdapter() {
            public void keyPressed(java.awt.event.KeyEvent evt) {
                txtLocalidadKeyPressed(evt);
            }
            public void keyTyped(java.awt.event.KeyEvent evt) {
                txtLocalidadKeyTyped(evt);
            }
        });

        jLabel9.setText("Localidad:");

        cmbPais.setModel(new javax.swing.DefaultComboBoxModel(new String[] { "Item 1", "Item 2", "Item 3", "Item 4" }));

        javax.swing.GroupLayout jPanel3Layout = new javax.swing.GroupLayout(jPanel3);
        jPanel3.setLayout(jPanel3Layout);
        jPanel3Layout.setHorizontalGroup(
            jPanel3Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel3Layout.createSequentialGroup()
                .addContainerGap()
                .addGroup(jPanel3Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING, false)
                    .addComponent(jLabel9, javax.swing.GroupLayout.PREFERRED_SIZE, 80, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(jLabel7, javax.swing.GroupLayout.PREFERRED_SIZE, 80, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                .addGroup(jPanel3Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(jPanel3Layout.createSequentialGroup()
                        .addComponent(cmbPais, javax.swing.GroupLayout.PREFERRED_SIZE, 110, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addComponent(jLabel6)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                        .addComponent(txtProvincia, javax.swing.GroupLayout.DEFAULT_SIZE, 99, Short.MAX_VALUE))
                    .addComponent(txtLocalidad, javax.swing.GroupLayout.DEFAULT_SIZE, 303, Short.MAX_VALUE))
                .addContainerGap())
        );

        jPanel3Layout.linkSize(javax.swing.SwingConstants.HORIZONTAL, new java.awt.Component[] {jLabel6, jLabel7, jLabel9});

        jPanel3Layout.setVerticalGroup(
            jPanel3Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel3Layout.createSequentialGroup()
                .addGroup(jPanel3Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jLabel7)
                    .addComponent(jLabel6)
                    .addComponent(txtProvincia, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(cmbPais, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                .addGroup(jPanel3Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jLabel9)
                    .addComponent(txtLocalidad, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addContainerGap())
        );

        jPanel4.setBorder(javax.swing.BorderFactory.createTitledBorder("Información Personal"));
        jPanel4.setOpaque(false);

        jLabel2.setText("<html>Nombres: <font color=\"red\">(*)</font> </html>");

        jLabel3.setText("<html>Apellidos: <font color=\"red\">(*)</font> </html>");

        txtNombres.addKeyListener(new java.awt.event.KeyAdapter() {
            public void keyPressed(java.awt.event.KeyEvent evt) {
                txtNombresKeyPressed(evt);
            }
            public void keyTyped(java.awt.event.KeyEvent evt) {
                txtNombresKeyTyped(evt);
            }
        });

        txtApellidos.addKeyListener(new java.awt.event.KeyAdapter() {
            public void keyPressed(java.awt.event.KeyEvent evt) {
                txtApellidosKeyPressed(evt);
            }
            public void keyTyped(java.awt.event.KeyEvent evt) {
                txtApellidosKeyTyped(evt);
            }
        });

        dateFechaNac.setDateFormatString("dd/MM/yyyy");
        dateFechaNac.addKeyListener(new java.awt.event.KeyAdapter() {
            public void keyPressed(java.awt.event.KeyEvent evt) {
                dateFechaNacKeyPressed(evt);
            }
        });

        jLabel4.setText("<html>Fecha Nac.: <font color=\"red\">(*)</font> </html>");

        jLabel10.setText("Teléfono:");

        txtTelefono.addKeyListener(new java.awt.event.KeyAdapter() {
            public void keyPressed(java.awt.event.KeyEvent evt) {
                txtTelefonoKeyPressed(evt);
            }
            public void keyTyped(java.awt.event.KeyEvent evt) {
                txtTelefonoKeyTyped(evt);
            }
        });

        txtNacionalidad.addKeyListener(new java.awt.event.KeyAdapter() {
            public void keyPressed(java.awt.event.KeyEvent evt) {
                txtNacionalidadKeyPressed(evt);
            }
            public void keyTyped(java.awt.event.KeyEvent evt) {
                txtNacionalidadKeyTyped(evt);
            }
        });

        jLabel5.setText("Nacionalidad:");

        javax.swing.GroupLayout jPanel4Layout = new javax.swing.GroupLayout(jPanel4);
        jPanel4.setLayout(jPanel4Layout);
        jPanel4Layout.setHorizontalGroup(
            jPanel4Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel4Layout.createSequentialGroup()
                .addContainerGap()
                .addGroup(jPanel4Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false)
                    .addComponent(jLabel5, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                    .addComponent(jLabel4)
                    .addComponent(jLabel3)
                    .addComponent(jLabel2, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addGap(20, 20, 20)
                .addGroup(jPanel4Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(txtNacionalidad, javax.swing.GroupLayout.DEFAULT_SIZE, 298, Short.MAX_VALUE)
                    .addComponent(txtNombres, javax.swing.GroupLayout.DEFAULT_SIZE, 298, Short.MAX_VALUE)
                    .addComponent(txtApellidos, javax.swing.GroupLayout.DEFAULT_SIZE, 298, Short.MAX_VALUE)
                    .addGroup(jPanel4Layout.createSequentialGroup()
                        .addComponent(dateFechaNac, javax.swing.GroupLayout.PREFERRED_SIZE, 106, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                        .addComponent(jLabel10, javax.swing.GroupLayout.PREFERRED_SIZE, 67, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addComponent(txtTelefono, javax.swing.GroupLayout.DEFAULT_SIZE, 111, Short.MAX_VALUE)))
                .addContainerGap())
        );

        jPanel4Layout.linkSize(javax.swing.SwingConstants.HORIZONTAL, new java.awt.Component[] {jLabel2, jLabel3, jLabel4, jLabel5});

        jPanel4Layout.setVerticalGroup(
            jPanel4Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel4Layout.createSequentialGroup()
                .addGroup(jPanel4Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jLabel2, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(txtNombres, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                .addGroup(jPanel4Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jLabel3, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(txtApellidos, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(jPanel4Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
                    .addComponent(jLabel4, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addGroup(jPanel4Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                        .addComponent(jLabel10)
                        .addComponent(txtTelefono, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                    .addComponent(dateFechaNac, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(jPanel4Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(txtNacionalidad, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(jLabel5))
                .addGap(4, 4, 4))
        );

        jPanel5.setBorder(javax.swing.BorderFactory.createTitledBorder("Información Técnica"));
        jPanel5.setOpaque(false);

        jLabel11.setText("<html>Tipo Licencia: <font color=\"red\">(*)</font> </html>");

        txtTipoLic.addKeyListener(new java.awt.event.KeyAdapter() {
            public void keyPressed(java.awt.event.KeyEvent evt) {
                txtTipoLicKeyPressed(evt);
            }
            public void keyTyped(java.awt.event.KeyEvent evt) {
                txtTipoLicKeyTyped(evt);
            }
        });

        javax.swing.GroupLayout jPanel5Layout = new javax.swing.GroupLayout(jPanel5);
        jPanel5.setLayout(jPanel5Layout);
        jPanel5Layout.setHorizontalGroup(
            jPanel5Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel5Layout.createSequentialGroup()
                .addContainerGap()
                .addComponent(jLabel11, javax.swing.GroupLayout.PREFERRED_SIZE, 93, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(txtTipoLic, javax.swing.GroupLayout.PREFERRED_SIZE, 135, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addContainerGap(171, Short.MAX_VALUE))
        );
        jPanel5Layout.setVerticalGroup(
            jPanel5Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel5Layout.createSequentialGroup()
                .addGroup(jPanel5Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jLabel11, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(txtTipoLic, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
        );

        jTabbedPane1.setBackground(new java.awt.Color(188, 211, 226));

        txtpObservacion.addKeyListener(new java.awt.event.KeyAdapter() {
            public void keyTyped(java.awt.event.KeyEvent evt) {
                txtpObservacionKeyTyped(evt);
            }
        });
        jScrollPane2.setViewportView(txtpObservacion);

        jTabbedPane1.addTab("Observaciones", jScrollPane2);

        javax.swing.GroupLayout jPanel1Layout = new javax.swing.GroupLayout(jPanel1);
        jPanel1.setLayout(jPanel1Layout);
        jPanel1Layout.setHorizontalGroup(
            jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, jPanel1Layout.createSequentialGroup()
                .addContainerGap()
                .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
                    .addComponent(jTabbedPane1, javax.swing.GroupLayout.Alignment.LEADING, javax.swing.GroupLayout.DEFAULT_SIZE, 425, Short.MAX_VALUE)
                    .addComponent(jPanel4, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                    .addComponent(jPanel3, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                    .addComponent(jPanel5, javax.swing.GroupLayout.Alignment.LEADING, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
                .addContainerGap())
        );
        jPanel1Layout.setVerticalGroup(
            jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel1Layout.createSequentialGroup()
                .addContainerGap()
                .addComponent(jPanel4, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(jPanel3, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(jPanel5, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(jTabbedPane1, javax.swing.GroupLayout.DEFAULT_SIZE, 94, Short.MAX_VALUE)
                .addContainerGap())
        );

        getContentPane().add(jPanel1, java.awt.BorderLayout.CENTER);

        jToolBar1.setBorder(javax.swing.BorderFactory.createEtchedBorder());
        jToolBar1.setFloatable(false);
        jToolBar1.setRollover(true);
        jToolBar1.setOpaque(false);

        jPanel2.setBackground(new java.awt.Color(255, 255, 255));
        jPanel2.setLayout(new java.awt.FlowLayout(java.awt.FlowLayout.LEFT));

        btnGuardar.setIcon(new javax.swing.ImageIcon(getClass().getResource("/com/camachosanchez/recursos/24_save.png"))); // NOI18N
        btnGuardar.setToolTipText("Guardar");
        btnGuardar.setBorder(javax.swing.BorderFactory.createLineBorder(new java.awt.Color(0, 0, 0)));
        btnGuardar.setFocusable(false);
        btnGuardar.setHorizontalTextPosition(javax.swing.SwingConstants.RIGHT);
        btnGuardar.setMaximumSize(new java.awt.Dimension(22, 22));
        btnGuardar.setMinimumSize(new java.awt.Dimension(22, 22));
        btnGuardar.setPreferredSize(new java.awt.Dimension(22, 22));
        btnGuardar.setVerticalTextPosition(javax.swing.SwingConstants.BOTTOM);
        btnGuardar.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                btnGuardarActionPerformed(evt);
            }
        });
        jPanel2.add(btnGuardar);

        btnElminar.setIcon(new javax.swing.ImageIcon(getClass().getResource("/com/camachosanchez/recursos/24_delete.png"))); // NOI18N
        btnElminar.setToolTipText("Eliminar");
        btnElminar.setBorder(javax.swing.BorderFactory.createLineBorder(new java.awt.Color(0, 0, 0)));
        btnElminar.setFocusable(false);
        btnElminar.setHorizontalTextPosition(javax.swing.SwingConstants.RIGHT);
        btnElminar.setMaximumSize(new java.awt.Dimension(22, 22));
        btnElminar.setMinimumSize(new java.awt.Dimension(22, 22));
        btnElminar.setPreferredSize(new java.awt.Dimension(22, 22));
        btnElminar.setVerticalTextPosition(javax.swing.SwingConstants.BOTTOM);
        btnElminar.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                btnElminarActionPerformed(evt);
            }
        });
        jPanel2.add(btnElminar);

        jToolBar1.add(jPanel2);

        getContentPane().add(jToolBar1, java.awt.BorderLayout.PAGE_START);

        pack();
    }// </editor-fold>//GEN-END:initComponents

    private void txtNombresKeyTyped(java.awt.event.KeyEvent evt) {//GEN-FIRST:event_txtNombresKeyTyped
        // TODO add your handling code here:
        char caracter = evt.getKeyChar();
        String caracteres = this.txtNombres.getText();
        if ((!(Character.isLetter(caracter)) && (caracter != KeyEvent.VK_SPACE)) || (caracteres.length() >= 50)) {
            evt.consume();
        }
    }//GEN-LAST:event_txtNombresKeyTyped

    private void txtApellidosKeyTyped(java.awt.event.KeyEvent evt) {//GEN-FIRST:event_txtApellidosKeyTyped
        // TODO add your handling code here:
        char caracter = evt.getKeyChar();
        String caracteres = this.txtApellidos.getText();
        if ((!(Character.isLetter(caracter)) && (caracter != KeyEvent.VK_SPACE)) || (caracteres.length() >= 50)) {
            evt.consume();
        }
    }//GEN-LAST:event_txtApellidosKeyTyped

    private void txtTelefonoKeyTyped(java.awt.event.KeyEvent evt) {//GEN-FIRST:event_txtTelefonoKeyTyped
        // TODO add your handling code here:
        String caracteres = this.txtTelefono.getText();
        if (caracteres.length() >= 20) {
            evt.consume();
        }
    }//GEN-LAST:event_txtTelefonoKeyTyped

    private void txtNacionalidadKeyTyped(java.awt.event.KeyEvent evt) {//GEN-FIRST:event_txtNacionalidadKeyTyped
        // TODO add your handling code here:
        char caracter = evt.getKeyChar();
        String caracteres = this.txtNacionalidad.getText();
        if ((!(Character.isLetter(caracter)) && (caracter != KeyEvent.VK_SPACE)) || (caracteres.length() >= 50)) {
            evt.consume();
        }
    }//GEN-LAST:event_txtNacionalidadKeyTyped

    private void txtProvinciaKeyTyped(java.awt.event.KeyEvent evt) {//GEN-FIRST:event_txtProvinciaKeyTyped
        // TODO add your handling code here:
        char caracter = evt.getKeyChar();
        String caracteres = this.txtProvincia.getText();
        if ((!(Character.isLetter(caracter)) && (caracter != KeyEvent.VK_SPACE)) || (caracteres.length() >= 45)) {
            evt.consume();
        }
    }//GEN-LAST:event_txtProvinciaKeyTyped

    private void txtLocalidadKeyTyped(java.awt.event.KeyEvent evt) {//GEN-FIRST:event_txtLocalidadKeyTyped
        // TODO add your handling code here:
        char caracter = evt.getKeyChar();
        String caracteres = this.txtLocalidad.getText();
        if ((!(Character.isLetter(caracter)) && (caracter != KeyEvent.VK_SPACE)) || (caracteres.length() >= 45)) {
            evt.consume();
        }
    }//GEN-LAST:event_txtLocalidadKeyTyped

    private void txtTipoLicKeyTyped(java.awt.event.KeyEvent evt) {//GEN-FIRST:event_txtTipoLicKeyTyped
        // TODO add your handling code here:
        String caracteres = this.txtTipoLic.getText();
        if (caracteres.length() >= 15) {
            evt.consume();
        }
    }//GEN-LAST:event_txtTipoLicKeyTyped

    private void txtNombresKeyPressed(java.awt.event.KeyEvent evt) {//GEN-FIRST:event_txtNombresKeyPressed
        // TODO add your handling code here:
        if (evt.getKeyCode() == KeyEvent.VK_ENTER) {
            this.txtApellidos.requestFocusInWindow();
        }
    }//GEN-LAST:event_txtNombresKeyPressed

    private void txtApellidosKeyPressed(java.awt.event.KeyEvent evt) {//GEN-FIRST:event_txtApellidosKeyPressed
        // TODO add your handling code here:
        if (evt.getKeyCode() == KeyEvent.VK_ENTER) {
            this.dateFechaNac.requestFocusInWindow();
        }
    }//GEN-LAST:event_txtApellidosKeyPressed

    private void dateFechaNacKeyPressed(java.awt.event.KeyEvent evt) {//GEN-FIRST:event_dateFechaNacKeyPressed
        // TODO add your handling code here:
        if (evt.getKeyCode() == KeyEvent.VK_ENTER) {
            this.txtTelefono.requestFocusInWindow();
        }
    }//GEN-LAST:event_dateFechaNacKeyPressed

    private void txtTelefonoKeyPressed(java.awt.event.KeyEvent evt) {//GEN-FIRST:event_txtTelefonoKeyPressed
        // TODO add your handling code here:
        if (evt.getKeyCode() == KeyEvent.VK_ENTER) {
            this.txtNacionalidad.requestFocusInWindow();
        }
    }//GEN-LAST:event_txtTelefonoKeyPressed

    private void txtNacionalidadKeyPressed(java.awt.event.KeyEvent evt) {//GEN-FIRST:event_txtNacionalidadKeyPressed
        // TODO add your handling code here:
        if (evt.getKeyCode() == KeyEvent.VK_ENTER) {
            cmbPais.requestFocusInWindow();
        }
    }//GEN-LAST:event_txtNacionalidadKeyPressed

    private void txtProvinciaKeyPressed(java.awt.event.KeyEvent evt) {//GEN-FIRST:event_txtProvinciaKeyPressed
        // TODO add your handling code here:
        if (evt.getKeyCode() == KeyEvent.VK_ENTER) {
            this.txtLocalidad.requestFocusInWindow();
        }
    }//GEN-LAST:event_txtProvinciaKeyPressed

    private void txtLocalidadKeyPressed(java.awt.event.KeyEvent evt) {//GEN-FIRST:event_txtLocalidadKeyPressed
        // TODO add your handling code here:
        if (evt.getKeyCode() == KeyEvent.VK_ENTER) {
            this.txtTipoLic.requestFocusInWindow();
        }
    }//GEN-LAST:event_txtLocalidadKeyPressed

    private void txtTipoLicKeyPressed(java.awt.event.KeyEvent evt) {//GEN-FIRST:event_txtTipoLicKeyPressed
        // TODO add your handling code here:
        if (evt.getKeyCode() == KeyEvent.VK_ENTER) {
            this.txtpObservacion.requestFocusInWindow();
        }
    }//GEN-LAST:event_txtTipoLicKeyPressed

private void btnGuardarActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btnGuardarActionPerformed
// TODO add your handling code here:
    if (ValidarDatos()) {
        GuardarDatos();
    }
}//GEN-LAST:event_btnGuardarActionPerformed

    private void btnElminarActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btnElminarActionPerformed
        // TODO add your handling code here:
        if (JOptionPane.showConfirmDialog(null, "¿Está seguro que desea eliminar este piloto?", "Confirmación", JOptionPane.YES_NO_OPTION) == JOptionPane.YES_OPTION) {
            PilotosJdbcControler daoJdbc = new PilotosJdbcControler();
            byte estado = daoJdbc.eliminarPiloto(this.piloto.getId());
            if (estado == 1) {
                JOptionPane.showMessageDialog(this, "El piloto se encuentra relacionado con otros registros, no puede ser eliminado.", "Error en la eliminación", JOptionPane.ERROR_MESSAGE);
            } else {
                JOptionPane.showMessageDialog(this, "El piloto se ha eliminado de forma segura.", "Operación finalizada", JOptionPane.INFORMATION_MESSAGE);
                buscador.borrarPiloto(fila);
                dispose();
            }
        }
    }//GEN-LAST:event_btnElminarActionPerformed

    private void txtpObservacionKeyTyped(java.awt.event.KeyEvent evt) {//GEN-FIRST:event_txtpObservacionKeyTyped
        // TODO add your handling code here:
        String caracteres = this.txtpObservacion.getText();
        if (caracteres.length() >= 200) {
            evt.consume();
        }
    }//GEN-LAST:event_txtpObservacionKeyTyped
    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.JButton btnElminar;
    private javax.swing.JButton btnGuardar;
    private javax.swing.JComboBox cmbPais;
    private com.toedter.calendar.JDateChooser dateFechaNac;
    private javax.swing.JLabel jLabel10;
    private javax.swing.JLabel jLabel11;
    private javax.swing.JLabel jLabel2;
    private javax.swing.JLabel jLabel3;
    private javax.swing.JLabel jLabel4;
    private javax.swing.JLabel jLabel5;
    private javax.swing.JLabel jLabel6;
    private javax.swing.JLabel jLabel7;
    private javax.swing.JLabel jLabel9;
    private javax.swing.JPanel jPanel1;
    private javax.swing.JPanel jPanel2;
    private javax.swing.JPanel jPanel3;
    private javax.swing.JPanel jPanel4;
    private javax.swing.JPanel jPanel5;
    private javax.swing.JScrollPane jScrollPane2;
    private javax.swing.JTabbedPane jTabbedPane1;
    private javax.swing.JToolBar jToolBar1;
    private javax.swing.JTextField txtApellidos;
    private javax.swing.JTextField txtLocalidad;
    private javax.swing.JTextField txtNacionalidad;
    private javax.swing.JTextField txtNombres;
    private javax.swing.JTextField txtProvincia;
    private javax.swing.JTextField txtTelefono;
    private javax.swing.JTextField txtTipoLic;
    private javax.swing.JTextPane txtpObservacion;
    // End of variables declaration//GEN-END:variables
}
